package com.datam.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.datam.dao.ConpanyTxInfoDAO;
import com.datam.domain.CompanyPkInfoDO;
import com.datam.domain.ConpanyTxInfoDO;
import com.datam.domain.SysUserDO;
import com.datam.query.QueryCompanyPkInfo;
import com.datam.query.QueryConpanyTxInfo;
import com.datam.utils.DMResult;

@Controller
public class TXController {
	
	private static Logger logger = LoggerFactory.getLogger(PKController.class);
	
	@Autowired
	ConpanyTxInfoDAO conpanyTxInfoDAO	;
	
	
	@RequestMapping("VOCsCompany/GetTXInfoData")
	public @ResponseBody Object GetTXInfoData(HttpServletRequest request, HttpServletResponse response,
			long ID){
		try {
			QueryConpanyTxInfo queryConpanyTxInfo = new QueryConpanyTxInfo();
			queryConpanyTxInfo.setCOMPANYID(ID);
			List< ConpanyTxInfoDO > data = conpanyTxInfoDAO.selectConpanyTxInfoList(queryConpanyTxInfo);
			Map r = new HashMap();
			r.put("total", data.size());
			r.put("rows", data);
			return r ;
		}catch (Exception e) {
			e.printStackTrace();
			return new DMResult("操作失败",false);
		}
	}
	
	@RequestMapping("VOCsCompany/GetTXInfoInfoByID")
	public @ResponseBody Object GetCompanyInfoByID(HttpServletRequest request, HttpServletResponse response,
			Long rowID,Long PKID ){
		try {
			QueryConpanyTxInfo queryConpanyTxInfo = new QueryConpanyTxInfo();
			queryConpanyTxInfo.setPKID(PKID);
			queryConpanyTxInfo.setID(rowID);
			return new DMResult(conpanyTxInfoDAO.selectConpanyTxInfoList(queryConpanyTxInfo),"查询成功",true);
		}catch (Exception e) {
				e.printStackTrace();
				return new DMResult("操作失败",false);
			}
	}
	
	@RequestMapping("VOCsCompany/saveTXInfoData")
	public @ResponseBody Object saveTXInfoData(HttpServletRequest request, HttpServletResponse response,
			ConpanyTxInfoDO conpanyTxInfoDO){
		try {
			if(conpanyTxInfoDO.getID() == null){
				conpanyTxInfoDAO.insertConpanyTxInfo(conpanyTxInfoDO);
			}else{
				conpanyTxInfoDAO.updateConpanyTxInfoById(conpanyTxInfoDO);
			}
			return new DMResult("插入成功",true);
		}catch (Exception e) {
			e.printStackTrace();
			return new DMResult("操作失败",false);
		}
	}
	
	@RequestMapping("VOCsCompany/DelTXInfoInfoByID")
	public @ResponseBody Object DelTXInfoInfoByID(HttpServletRequest request, HttpServletResponse response,
			long id){
		try {
			conpanyTxInfoDAO.deleteTX(id);
			return new DMResult("删除成功",true);
		}catch (Exception e) {
			e.printStackTrace();
			return new DMResult("操作失败",false);
		}
	}

}
